<template>
    <div class="center_div">
        <el-table :data="prizeList" v-loading="tableLoading" element-loading-text="Loading">
            <el-table-column prop="awardid" label="编号" min-width="70"></el-table-column>
            <el-table-column prop="awardname" label="奖品名" min-width="90"></el-table-column>
            <el-table-column label="操作" min-width="150" align="center">
                <template slot-scope="scope">
                    <el-button type="warning" @click="editPrize(scope.row)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>


        <el-dialog
                title="编辑奖品信息"
                :visible.sync="dialogVisible"
                width="50%">
            <el-form ref="form" :model="prizeDetail" label-width="100px" style="margin-top:50px;">
                <el-form-item label="编号" prop="awardid">
                    <el-input v-model="prizeDetail.awardid" disabled style="width: 50%;"></el-input>
                </el-form-item>
                <el-form-item label="奖品" prop="awardname">
                    <el-input v-model="prizeDetail.awardname" style="width: 50%;"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="updatePrize">更新</el-button>
              </span>
        </el-dialog>
    </div>
</template>
<script>
    export default{
        name: "admin-prize",
        data() {
            return {
                prizeList:[],
                prizeDetail: {},
                dialogVisible: false,
                tableLoading: false
            }
        },
        created() {
            this.fetchAward()
        },
        methods:{
            async fetchAward() {
                this.tableLoading = true
                let {code ,data ,msg} = await this.$post('/managerboss/updateaward')
                if(code === 200) {
                    console.log(data)
                    this.prizeList = data
                    console.log(this.prizeList)
                }else {
                    this.$message.error(msg)
                }
                this.tableLoading = false
            },
            editPrize(row) {
                this.prizeDetail = row
                this.dialogVisible = true
            },
            async updatePrize() {
                let {code ,data ,msg} = await this.$post('/managerboss/editaward',{
                    data: {id: this.prizeDetail.awardid, name: this.prizeDetail.awardname}
                })
                if(code === 200) {
                    console.log(data)
                    this.$message({
                        message: '奖品修改成功',
                        type: 'success'
                    })
                    this.fetchAward()
                    this.dialogVisible = false
                }else {
                    this.$message.error(msg)
                }
            }
        }
    }
</script>

<style >
    .center_div{
        width: 90%;
        margin:0 auto;
        margin-bottom: 50px;
    }
</style>